define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'statistics/materialplanaudit/index' + location.search,
                    table: 'material_plan_audit',
                },
                pageSize: 15,
                pageList: [15],
            });

            //搜索默认选中驳回
            var table = $("#table");
            // table.on('post-common-search.bs.table', function (event, table) {
            //     $('ul.nav-tabs li a[data-value="2"]').trigger('click');
            //     $(".form-commonsearch select[name=status]").val("2");
            // });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible:true,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'trademark_printing', title: __('Trademark_printing'), operate: 'LIKE'},
                        {field: 'abbreviation', title: __('Abbreviation'), operate: 'LIKE'},
                        {field: 'colour.name', title: __('Colour.name'), operate: 'LIKE'},
                        {field: 'finished_weight', title: __('Finished_weight'), operate:'BETWEEN'},
                        {field: 'feeding_weight', title: __('Feeding_weight'), operate:'BETWEEN'},
                        {field: 'attrition_rate', title: __('Attrition_rate'), operate:'BETWEEN'},
                        {field: 'attribute', title: __('Attribute'), searchList: {"0":__('Attribute 0'),"1":__('Attribute 1')}, formatter: Table.api.formatter.normal},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
                        {field: 'createuser.nickname', title: __('CreateUser.nickname'), operate: 'LIKE'},
                        {field: 'audittime', title: __('Audittime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'ddd', title: __('操作'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: '查看',
                                    title: '查看',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-info btn-detail btn-dialog',
                                    url: 'statistics/materialplanaudit/edit?type=materialplandetail'
                                },
                                {
                                    name: 'audit',
                                    text: '审核',
                                    title: '审核',
                                    icon: 'fa fa-magic',
                                    classname: 'btn btn-xs btn-info btn-audit btn-dialog',
                                    url: 'statistics/materialplanaudit/audit',
                                    success:function (data,ret) {
                                        layer.alert(ret.msg)
                                    },
                                    visible: function (row) {
                                        return row.status == 0 ? true : false;
                                        // return true;
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
            $(document).on("fa.event.appendfieldlist", ".btn-append", function(){
                Form.events.selectpage($("#j-longlist"));
                Form.events.selectpage($("#j-shortlist"));
            });
        },
        edit: function () {
            Controller.api.bindevent();
            $(document).on("fa.event.appendfieldlist", ".btn-append", function(){
                Form.events.selectpage($("#j-longlist"));
                Form.events.selectpage($("#j-shortlist"));
            });
        },
        audit: function () {
            console.log(111111)
            Controller.api.bindevent();
            $(document).on("fa.event.appendfieldlist", ".btn-append", function(){
                Form.events.selectpage($("#j-longlist"));
                Form.events.selectpage($("#j-shortlist"));
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
